package com.pulse.common.utils.sor.make;

import com.pulse.common.utils.sor.domain.SorInfo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * @ClassName MapMake
 * @Description
 * @Author 陆帅
 * @Date 2025/3/14 23:32
 */
public class MapMake {

    private static final String MAP_BLOCK_ID = "Map\0";


    public static ByteBuffer make(SorInfo info) {
        ByteBuffer buffer = ByteBuffer.allocate(128);
        buffer.order(ByteOrder.LITTLE_ENDIAN);

        // 块ID
        buffer.put(MAP_BLOCK_ID.getBytes());

        // 修订号
        String version = info.getVersion() == null ? "2.00" : info.getVersion();
        Double versionD = Double.parseDouble(version) * 100;
        buffer.putShort(versionD.shortValue());
        //写入 Map Block大小 (暂时填充 0，后续更新)
        buffer.putInt(0);
        // 写入块数量
        buffer.putShort((short)info.getMapblock().getNblocks());

        return buffer;
    }
}
